home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / COMMON / dosstick.c < prev    next >
C/C++ Source or Header  |  1995-08-28  |  3KB  |  173 lines

  1. /* --------------------------------- dosstick.c ----------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Low level joystick reading.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12. #ifdef HAVE_JOYSTICK
  13.  
  14. #include "stick.h"
  15.  
  16.  
  17. #ifdef DJGPP
  18. #include <pc.h>
  19. #define inp(p)         inportb(p)
  20. #define outp(p,b)    outportb(p,b)
  21. #else
  22. #include <dos.h>
  23. #include <conio.h>
  24. #endif
  25.  
  26.  
  27. /* First (lowest) level PC joystick reading. Acquires hardware dependent
  28.  * data as is.
  29. */
  30.  
  31. #define GAME_PORT    0x0201
  32. #define GAME_TIMEOUT    0xffffU        /* counter!!! */
  33. #define GAME_START    (outp (GAME_PORT, 0), iefbr14 ())
  34. #define GAME_READ    inp (GAME_PORT)
  35. #define GAME_READING    (Ushort)(mode ? Tm->Hires () : GAME_TIMEOUT-i)
  36.  
  37. /* Bit mapping for the PC games port status byte.
  38. */
  39. #define GAME_X1        0x001
  40. #define GAME_Y1        0x002
  41. #define GAME_X2        0x004
  42. #define GAME_Y2        0x008
  43. #define GAME_B1        0x010
  44. #define GAME_B2        0x020
  45. #define GAME_B3        0x040
  46. #define GAME_B4        0x080
  47.  
  48. extern int FAR
  49. initstick (int which, char *options, int opts)
  50. {return (0);}
  51.  
  52. extern int FAR
  53. termstick (int which, int opts)
  54. {return (0);}
  55.  
  56. extern Uint FAR
  57. readstick (int which, STICK *s, int mask, int opts)
  58. {
  59.     register Ushort    i;
  60.     register Uint    m;
  61.     Ushort        t, tt, x1, y1, x2, y2;
  62.     int        js, mode;
  63.  
  64.     mode = opts & USETIMER;
  65.  
  66.     i = GAME_TIMEOUT;
  67.     t = GAME_READING;
  68.     x1 = y1 = x2 = y2 = t;
  69.  
  70.     m = 0;
  71.     if (which) {
  72.         if (mask & JS_X1)
  73.             m |= GAME_X2;
  74.         if (mask & JS_Y1)
  75.             m |= GAME_Y2;
  76.     } else {
  77.         if (mask & JS_X1)
  78.             m |= GAME_X1;
  79.         if (mask & JS_Y1)
  80.             m |= GAME_Y1;
  81.         if (mask & JS_X2)
  82.             m |= GAME_X2;
  83.         if (mask & JS_Y2)
  84.             m |= GAME_Y2;
  85.     }
  86.     GAME_START;            /* set trigger */
  87.     while (m) {
  88.         while (!(~GAME_READ & m) && --i)
  89.             ;
  90.         if (!i)
  91.             break;
  92.         tt = GAME_READING;
  93.         js = ~GAME_READ & m;
  94.         if (js & 0x01) {
  95.             x1 = tt;
  96.             m &= ~GAME_X1;
  97.         }
  98.         if (js & 0x02) {
  99.             y1 = tt;
  100.             m &= ~GAME_Y1;
  101.         }
  102.         if (js & 0x04) {
  103.             x2 = tt;
  104.             m &= ~GAME_X2;
  105.         }
  106.         if (js & 0x08) {
  107.             y2 = tt;
  108.             m &= ~GAME_Y2;
  109.         }
  110.     }
  111.  
  112. /* Set analog values.
  113. */
  114.     if (which) {
  115.         s->a[0] = x2 - t;
  116.         s->a[1] = y2 - t;
  117.     } else {
  118.         s->a[0] = x1 - t;
  119.         s->a[1] = y1 - t;
  120.         s->a[2] = x2 - t;
  121.         s->a[3] = y2 - t;
  122.     }
  123.  
  124. /* Set button values.
  125. */
  126.     js = ~GAME_READ;
  127.     if (which) {
  128.         s->b[0] = (Ushort)T(js & GAME_B3);
  129.         s->b[1] = (Ushort)T(js & GAME_B4);
  130.     } else {
  131.         s->b[0] = (Ushort)T(js & GAME_B1);
  132.         s->b[1] = (Ushort)T(js & GAME_B2);
  133.         s->b[2] = (Ushort)T(js & GAME_B3);
  134.         s->b[3] = (Ushort)T(js & GAME_B4);
  135.     }
  136.  
  137. /* Indicate analog failure.
  138. */
  139.     js = 0;
  140.     if (which) {
  141.         if (m & GAME_X2)
  142.             js |= JS_X1;
  143.         if (m & GAME_Y2)
  144.             js |= JS_Y1;
  145.     } else {
  146.         if (m & GAME_X1)
  147.             js |= JS_X1;
  148.         if (m & GAME_Y1)
  149.             js |= JS_Y1;
  150.         if (m & GAME_X2)
  151.             js |= JS_X2;
  152.         if (m & GAME_Y2)
  153.             js |= JS_Y2;
  154.     }
  155.  
  156.     return (js);
  157. }
  158. #undef GAME_PORT
  159. #undef GAME_TIMEOUT
  160. #undef GAME_START
  161. #undef GAME_READ
  162. #undef GAME_READING
  163. #undef GAME_X1
  164. #undef GAME_Y1
  165. #undef GAME_X2
  166. #undef GAME_Y2
  167. #undef GAME_B1
  168. #undef GAME_B2
  169. #undef GAME_B3
  170. #undef GAME_B4
  171.  
  172. #endif /* ifdef HAVE_JOYSTICK */
  173.